package master

import (
	"encoding/json"
	"io/ioutil"
)

type Config struct {
	ApiPort int	`json:"apiPort"`
	ApiReadTimeout int	`json:"apiReadTimeout"`
	ApiWriteTimeout int	`json:"apiWriteTimeout"`
	EtcdEndpoints []string `json:"etcdEndpoints"`
	EtcdDialTimeout int `json:"etcdDialTimeout"`
	WebRoot string `json:"webroot"`
	MongodbUri string `json:"mongodbUri"`
	MongodbConnectTimeout int `json:"mongodbConnectTimeout"`
}

var (
	G_config *Config
)

func InitConfig(configFile string) (err error) {
	var (
		content []byte
		config  Config
	)
	if content, err = ioutil.ReadFile(configFile); err != nil {
		return
	}

	if err = json.Unmarshal(content, &config); err != nil {
		return
	}

	// fmt.Println(config)

	G_config = &config

	return
}
